package com.pdg.android.rockscissorspaper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

public class SettingsActivity  extends Activity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        CheckBox theCheckBox = (CheckBox)findViewById(R.id.limited_checkbox);
        theCheckBox.setChecked(Settings.getRoundsFixed(this));
        EditText theEditText = (EditText)findViewById(R.id.limited_edit);
        theEditText.setText(String.format("%d",Settings.getRoundCount(this)));
        TextView theTextView = (TextView)findViewById(R.id.error_message);
        theTextView.setText(getString(R.string.empty_string));
    }
	public void backButtonPressed(View theView){
        CheckBox theCheckBox = (CheckBox)findViewById(R.id.limited_checkbox);
        Settings.setRoundsFixed(this,theCheckBox.isChecked());
        EditText theEditText = (EditText)findViewById(R.id.limited_edit);
        TextView theTextView = (TextView)findViewById(R.id.error_message);
        try{
	        Settings.setRoundCount(this,Integer.parseInt(theEditText.getText().toString()));
	        theTextView.setText(getString(R.string.empty_string));
	        Intent myIntent = new Intent(theView.getContext(), MainMenuActivity.class);
	        startActivityForResult(myIntent, 0);
        }
        catch(Exception e){
	        theTextView.setText(getString(R.string.invalid_value));
        }
	}
}
